
document.addEventListener('mousedown', function(event) {
  console.log('鼠标坐标：', event.clientX, event.clientY);
});

function simulateMouseEvent(element, eventType, options) {
  const event = new MouseEvent(eventType, options);
  element.dispatchEvent(event);
}

function randMove(element,X,Y,destination){
     // 在这里替换为你要模拟的事件数据
    var min = 1; // 范围的最小值
    var max = 10; // 范围的最大值
    var moveSize = Math.floor(Math.random() * (max - min + 1)) + min;
    var leftDestination = destination - moveSize;
    if(leftDestination < 0){
        leftDestination=0;
        moveSize = destination;
    }

    var moveX = X+moveSize;
    console.log("randMove_"+"__"+moveX+"__"+leftDestination);

    const eventOptions1 = {
      bubbles: true,
      cancelable: true,
      clientX: moveX,
      clientY: Y,
      screenX:moveX,
      screenY:Y
    };
    if(leftDestination > 0){
        setTimeout(() => {
            simulateMouseEvent(element, "mousemove", eventOptions1);
            randMove(element,moveX,Y,leftDestination);
        },10);
    }else{
        setTimeout(() => {
            simulateMouseEvent(element, "mousemove", eventOptions1);
        },10);
        setTimeout(() => {
            simulateMouseEvent(element, "mouseup", eventOptions1);
        },100);
    }

}

doMain();
function doMain(){
       setTimeout(() => {

            // 在这里替换为你要模拟的元素
           const element = document.getElementById("nc_1_n1z");
           var buttonDiv = $("#nc_1_n1z");
           var rect = buttonDiv.offset();
           console.log(rect)
           if(!rect){
                //循环等到有这元素
                doMain();
                return
           }
           var centerX = rect.left + buttonDiv.width() / 2;
           var centerY = rect.top + buttonDiv.height() / 2;
            console.log('坐标：', centerX, centerY);

            // 在这里替换为你要模拟的事件数据
            const eventOptions = {
              bubbles: true,
              cancelable: true,
              clientX: centerX,
              clientY: centerY,
              screenX:centerX,
              screenY:centerY
            };
            simulateMouseEvent(element, "mousedown", eventOptions);

            var buttonWidth = buttonDiv.width();
            var boxWidth = $("#nc_1__scale_text").width();
            var destination = boxWidth - buttonWidth;

            console.log(destination+"_"+boxWidth+"_"+buttonWidth)

            randMove(element,centerX,centerY,destination);

            var buttonDiv = $("#nc_1_n1z");




            if(buttonDiv){

                /*
                  // 模拟点击事件
                  buttonDiv.trigger($.Event("mousedown", {
                    clientX: centerX,
                    clientY: centerY
                  }));

                var buttonWidth = buttonDiv.width();
                var boxWidth = $("#nc_1__scale_text").width();
                console.log(buttonWidth)
                console.log(boxWidth)

                var destination = 200;//boxWidth - buttonWidth -50;
              // 模拟滑动操作
                setTimeout(() => {
                      buttonDiv.animate({
                        left: destination
                      },
                      {
                      duration:1000,
                      complete: function() {
                        // 模拟释放鼠标按键
                        buttonDiv.trigger($.Event("mouseup"));
                      },
                      step: function(now, tween) {

                            console.log(now)
                            console.log(tween)
                            var simulatedEvent = $.Event('mousemove');
                            simulatedEvent.clientX = destination;
                            buttonDiv.trigger(simulatedEvent);


                         }
                      });




                  },200);*/
            }

  }, 2000);

}



